//
//  XJStatusToolBarView.swift
//  XJWeiBO
//
//  Created by 452608533 on 16/7/24.
//  Copyright © 2016年 452608533. All rights reserved.
//

import UIKit

class XJStatusToolBarView: UIView {
    //评论
    var retweetButton: UIButton?
    //转发
    var commentButton: UIButton?
    //赞
    var unlikeButton: UIButton?
    
    //记住:statusViewModel1是在cell中进行赋值的
    var statusViewModel1: XJStatusViewModel?{
        
        didSet{
            retweetButton?.setTitle(statusViewModel1?.repostsCountStr, forState: UIControlState.Normal)
            commentButton?.setTitle(statusViewModel1?.commentsCountStr, forState: UIControlState.Normal)
            unlikeButton?.setTitle(statusViewModel1?.attitudesCountStr, forState: UIControlState.Normal)
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   private func setupUI() {
    
    backgroundColor = UIColor.whiteColor()
    
     retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
     commentButton = addChildButton("timeline_icon_comment", title: "评论")
     unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
    let line1 = addChildLine()
    let line2 = addChildLine()
    
    retweetButton!.snp_makeConstraints { (make) -> Void in
        make.top.bottom.leading.equalTo(self)
        make.width.equalTo(commentButton!)
    }
    commentButton!.snp_makeConstraints { (make) -> Void in
        make.top.bottom.equalTo(self)
        make.leading.equalTo(retweetButton!.snp_trailing)
        make.width.equalTo(unlikeButton!)
    }
    unlikeButton!.snp_makeConstraints { (make) -> Void in
        make.top.trailing.bottom.equalTo(self)
        make.leading.equalTo(commentButton!.snp_trailing)
    }
    line1.snp_makeConstraints { (make) -> Void in
        make.centerY.equalTo(self)
        make.centerX.equalTo(retweetButton!.snp_trailing)
    }
    line2.snp_makeConstraints { (make) -> Void in
        make.centerY.equalTo(self)
        make.centerX.equalTo(commentButton!.snp_trailing)
    }
}
    
    //添加按钮的公共方法
    func addChildButton(imgName: String, title: String) -> UIButton{
        let button = UIButton()
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        addSubview(button)
        return button
    }
    //分割线
    
    func addChildLine() -> UIImageView {
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        addSubview(img)
        return img
    }

}

